package com.broadtext.common.utils;

import java.io.IOException;
import java.util.List;

import org.apache.poi.ss.usermodel.Workbook;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;

import com.broadtext.rms.monitor.model.PackLocationInfo;

public class ExportThread extends Thread {
    
    
    private List<PackLocationInfo> loList;
    
    private String fileName;
    
    
    public ExportThread(List<PackLocationInfo> list, String filename){
        this.loList = list;
        this.fileName = filename;
    }
    
    @Override
    public void run() {
        for (int i = 0; i < loList.size(); i++) {
            if((null != loList.get(i).getLatitude() && !loList.get(i).getLatitude().trim().equals("")) && (null != loList.get(i).getLongitude()) && !loList.get(i).getLongitude().trim().equals("")){
                //gps转百度坐标
                String address = "";
                double[] JWD = BaiduAPI.wgs2bd(Double.valueOf(loList.get(i).getLatitude().trim()), Double.valueOf(loList.get(i).getLongitude().trim()));
                loList.get(i).setLatitude(String.valueOf(JWD[0]));
                loList.get(i).setLongitude(String.valueOf(JWD[1]));
                try {
                    address = BaiduAPI.DecodeLonLat(JWD[0], JWD[1]);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                loList.get(i).setAddress(address);
            } 
        }
        //导出
        ExportParams param;
        //标题 sheet名字
        param = new ExportParams("历史轨迹", "sheet");
        //excel类型 07或者03 不推荐07慢
        param.setType(ExcelType.XSSF);
        Workbook workbook = ExcelExportUtil.exportExcel(param, PackLocationInfo.class, loList);
        RmsUtil.saveExcel(fileName, workbook);
    }
}
